package com.lky.marshall.search.controller;

import com.lky.common.exception.BizCodeEnum;
import com.lky.common.to.es.SkuEsModle;
import com.lky.common.utils.R;
import com.lky.marshall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by
 * autor : Marshall lky
 * datetime: 2021/3/26 16:19
 */
@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    //上架商品
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModle> skuEsModles){
        boolean b =false;
        try {
            b = productSaveService.productStatusUp(skuEsModles);
        }catch (Exception e){
            log.error("商品上架出现异常:{}",e);
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),
                    BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if (!b) {
            return R.ok();
        }else {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),
                    BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }

}
